/**
\file IO.h
*/
#pragma once
#include <lostlbase.h>
#include <System.h>
#include "LoDll.h"

namespace lo {

	class Winspool : public dll
	{
	public:
		Winspool() : dll("winspool.drv") {}
		bool						addPortEx(const char * szStr, DWORD dwLevel, LPBYTE lpBuf, const char * szMonitorName );
		bool						addPrinterConnection(const char *driverName);
		void						addPrinter(PPRINTER_INFO_2W ppi2);
		void						closePrinter(HANDLE hPrinter);
		bool						deletePrinter(HANDLE hPrinter);
		bool						deletePrinterConnection(const char *printerName);
		bool						deletePrinterDriver( const char *printerName, const char *environment, const char *driverName );
		enum { Default = 1, Local = 2, ByName = 8, Shared = 0x20, Connections = 4, Network = 0x40, Remote = 0x10 };
		vector<string>				enumLocalPrinters( const char *driverName );
		/** Enumerate the ports, returning a PPORT_INFO_1W structure. */
		auto_ptr<PORT_INFO_1W>		enumPorts1( DWORD& numberOfPorts, const char *serverName = nullptr);
		/** Enumerate the ports, returning a PPORT_INFO_2W structure. */
		auto_ptr<PORT_INFO_2W>		enumPorts2( DWORD& numberOfPorts, const char *serverName = nullptr);
		/** Returns a DRIVER_INFO_* structure for the printer drivers located either locally or by the \p serverName using the \p environment. */
		auto_ptr<unsigned char>		enumPrinterDrivers( DWORD &numberOfDrivers, DWORD level, const char *serverName = nullptr, const char *environment = nullptr);
		auto_ptr<unsigned char>		getPrinter( _In_ HANDLE hPrinter, _In_ DWORD Level );
		/** */
		auto_ptr<unsigned char>		getPrinterDriver( _In_ HANDLE hPrinter, _In_ DWORD Level );
		string						getPrinterDriverDirectory();
		string						getPrintProcessorDirectory();
		bool						openPrinter( _In_ const char *printerName, _Out_ LPHANDLE phPrinter, _In_ LPPRINTER_DEFAULTS pDefault );

		bool						setPrinter( _In_ HANDLE hPrinter, _In_ DWORD level, _In_ LPBYTE printerInfo, _In_ DWORD command );
	protected:
		auto_ptr<unsigned char>		enumPrinters( DWORD flags, const char *name, DWORD level, DWORD & numberOfRecords );
		auto_ptr<unsigned char>		enumPorts( const char *name, DWORD Level, DWORD & numberOfRecords );
	};

}
